import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_layout/main/base_stateful_widget.dart';


class ListenerPage extends BaseStatefulWidget {
  const ListenerPage({Key? key}) : super(key: key);

  @override
  _ListenerPageState createState() => _ListenerPageState();
}

class _ListenerPageState extends State<ListenerPage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        centerTitle: true,
        title: Text( widget.runtimeType.toString()),
      ),
      body: Stack(
        alignment: Alignment.center,
        children: <Widget>[
          Listener(
            onPointerDown: (v) {
              if (kDebugMode) {
                print('click red');
              }
            },
            child: Container(
              color: Colors.red,
            ),
          ),
          Listener(
            onPointerDown: (v) {
              if (kDebugMode) {
                print('click blue self');
              }
            },
            //  child: IgnorePointer(
            //   child: Listener(
            //     onPointerDown: (v) {
            //       print('click blue child');
            //     },
            //     child: Container(
            //       color: Colors.blue,
            //       width: 100,
            //       height: 100,
            //     ),
            //   ),
            // ),
            // child: AbsorbPointer(
            //   child: Listener(
            //     onPointerDown: (v) {
            //       print('click blue child');
            //     },
            //     child: Container(
            //       color: Colors.blue,
            //       width: 100,
            //       height: 100,
            //     ),
            //   ),
            // ),
            child: Listener(
              onPointerDown: (v) {
                if (kDebugMode) {
                  print('click blue child');
                }
              },
              child: Container(
                color: Colors.blue,
                width: 100,
                height: 100,
              ),
            ),
          ),
        ],
      ),
    );
  }
}
/**
 * AbsorbPointer本身可以接收点击事件，消耗掉事件，而IgnorePointer无法接收点击事件，其下的控件可以接收到点击事件（不是子控件）。
 */